<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        .right {
            width: 200px;
            height: 200px;
            background: green;
        }

        .outer {
            width: 200px;
            height: 200px;
            background: pink;
        }

        .inner {
            width: 100px;
            height: 100px;
            background: orange;
        }

        .top{
            position: fixed;
            background: rgba(0,0,0,0.6);
            left:0;
            right:0;
            top:0;
            bottom:0;
        }
        .content{
            width: 300px;
            height: 200px;
            background: #fff;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>

<body>
    <!-- 定义挂载点 -->
    <div id="app">
        <!-- 默认事件 右击 .prevent:阻止默认行为 -->
        <div class="right" @contextmenu.prevent="right"></div>

        <!-- 事件冒泡 .stop : 阻止事件冒泡 -->
        <h2>事件冒泡</h2>
        <div class="outer" @click="outer">
            <div class="inner" @click.stop="inner"></div>
        </div>

        <!-- .once 只触发一次 -->
        <button @click.once="work">上班</button>

        <!-- .capture 事件捕获 -->
        <div class="outer" @click.capture="outer">
            <div class="inner" @click.capture="inner"></div>
        </div>

        <!-- .self 只能自己触发 -->
        <div class="box">
            <button @click="show">显示</button>
            <div class="top" v-if="isShow" @click.self="hide">
                <div class="content" >
                    <input type="text"><br><br><br>
                    <button>取消</button>
                    <button>确定</button>
                </div>
            </div>
        </div>
    </div>

    <script>
        new Vue({
            //挂载点
            el: "#app",
            //数据
            data: {
                isShow:false
            },
            //方法
            methods: {
                //阻止默认事件 -- 右击
                right() {
                    console.log("右击触发了");
                },

                // 事件冒泡
                outer() {
                    console.log("外面的盒子被点击了");
                },
                inner() {
                    console.log("里面的盒子被点击了");

                },
                work() {
                    console.log("每天上班");
                },
                show(){
                    this.isShow = true;
                },
                hide(){
                    this.isShow = false;
                },
                clickFun(){}
            }
        })
    </script>
</body>

</html>